package gui;

import enums.*;

import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SwingConstants;

public class TravelOptionsPanel extends JPanel {
	
	//boolean used to determine if the party needs to be initialized
	//or if the party's properties need to be changed
	//if onTrail = true then the group's pace/rations are just changed
	//if onTrail = false then the everything is initialized
	private boolean onTrail;

	// --------------------------- GUI COMPONENTS --------------------------- //
	
	private JRadioButton radioBtn_TO_Pace1;
	private JRadioButton radioBtn_TO_Pace2;
	private JRadioButton radioBtn_TO_Pace3;
	private JRadioButton radioBtn_TO_Pace4;

	private JRadioButton radioBtn_TO_Rations1;
	private JRadioButton radioBtn_TO_Rations2;
	private JRadioButton radioBtn_TO_Rations3;
	private JRadioButton radioBtn_TO_Rations4;
	
	private JLabel lblTravelTitle;
	private JLabel lblYourCurrentTravel;
	private JLabel lblYourCurrentRation;
	
	private final ButtonGroup travelPaceGroup = new ButtonGroup();
	private final ButtonGroup rationsGroup = new ButtonGroup();

	private JButton btnTravelContinue;
	private JButton btnBack;
	
	// --------------------------- GUI INIT --------------------------- //
	
	/**
	 * Creates the panel.
	 */
	public TravelOptionsPanel() {
		setLayout(null);
		
		onTrail = false;
		
		lblTravelTitle = new JLabel("Travel Options");
		lblTravelTitle.setBounds(10, 11, 684, 34);
		lblTravelTitle.setHorizontalAlignment(SwingConstants.CENTER);
		lblTravelTitle.setFont(new Font("Tahoma", Font.PLAIN, 30));
		add(lblTravelTitle);

		lblYourCurrentTravel = new JLabel("Your current travel pace");
		lblYourCurrentTravel.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblYourCurrentTravel.setBounds(37, 56, 444, 22);
		add(lblYourCurrentTravel);

		lblYourCurrentRation = new JLabel(
				"Your current ration consumption rate");
		lblYourCurrentRation.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblYourCurrentRation.setBounds(37, 217, 444, 22);
		add(lblYourCurrentRation);

		radioBtn_TO_Pace1 = new JRadioButton("Stopped");
		travelPaceGroup.add(radioBtn_TO_Pace1);
		radioBtn_TO_Pace1.setBounds(77, 85, 169, 23);
		add(radioBtn_TO_Pace1);

		radioBtn_TO_Pace2 = new JRadioButton("Slow - 5 miles per day");
		travelPaceGroup.add(radioBtn_TO_Pace2);
		radioBtn_TO_Pace2.setBounds(77, 111, 187, 23);
		add(radioBtn_TO_Pace2);

		radioBtn_TO_Pace3 = new JRadioButton("Medium - 10 miles per day");
		radioBtn_TO_Pace3.setSelected(true);
		travelPaceGroup.add(radioBtn_TO_Pace3);
		radioBtn_TO_Pace3.setBounds(77, 137, 209, 23);
		add(radioBtn_TO_Pace3);

		radioBtn_TO_Pace4 = new JRadioButton("Fast - 15 miles per day");
		travelPaceGroup.add(radioBtn_TO_Pace4);
		radioBtn_TO_Pace4.setBounds(77, 163, 187, 23);
		add(radioBtn_TO_Pace4);

		radioBtn_TO_Rations1 = new JRadioButton("Starving");
		rationsGroup.add(radioBtn_TO_Rations1);
		radioBtn_TO_Rations1.setBounds(77, 246, 308, 23);
		add(radioBtn_TO_Rations1);

		radioBtn_TO_Rations2 = new JRadioButton(
				"Low - 1 lbs of food per person per day");
		rationsGroup.add(radioBtn_TO_Rations2);
		radioBtn_TO_Rations2.setBounds(77, 272, 308, 23);
		add(radioBtn_TO_Rations2);

		radioBtn_TO_Rations3 = new JRadioButton(
				"Medium - 3 lbs of food per person per day");
		radioBtn_TO_Rations3.setSelected(true);
		rationsGroup.add(radioBtn_TO_Rations3);
		radioBtn_TO_Rations3.setBounds(77, 298, 308, 23);
		add(radioBtn_TO_Rations3);

		radioBtn_TO_Rations4 = new JRadioButton(
				"High - 5 lbs of food per person per day");
		rationsGroup.add(radioBtn_TO_Rations4);
		radioBtn_TO_Rations4.setBounds(77, 324, 308, 23);
		add(radioBtn_TO_Rations4);

		btnTravelContinue = new JButton("Continue");
		btnTravelContinue.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnTravelContinue.setBounds(273, 360, 180, 52);
		add(btnTravelContinue);
		
		btnBack = new JButton("Back");
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnBack.setBounds(636, 15, 60, 30);
		add(btnBack);
	}
	
	// --------------------------- GETTERS/SETTERS --------------------------- //
	
	public JButton getBackButton(){
		return btnBack;
	}
	
	public JButton getContinueButton(){
		return btnTravelContinue;
	}
	
	/**
	 * Returns the Ration Level (enum) selected by the user on the Travel
	 * Options page.
	 * 
	 * @return the new Ration Level
	 */
	public RationLevel getRationsSelection() {
		RationLevel current;
		if (radioBtn_TO_Rations1.isSelected()) {
			current = RationLevel.STARVING;
		} else if (radioBtn_TO_Rations2.isSelected()) {
			current = RationLevel.LOW;
		} else if (radioBtn_TO_Rations3.isSelected()) {
			current = RationLevel.MEDIUM;
		} else {
			current = RationLevel.HIGH;
		}
		return current;
	}

	/**
	 * Returns the Travel Pace (enum) selected by the user on the Travel Options
	 * page.
	 * 
	 * @return the new Travel Pace
	 */
	public TravelPace getTravelSelection() {
		TravelPace current;
		if (radioBtn_TO_Pace1.isSelected()) {
			current = TravelPace.STOPPED;
		} else if (radioBtn_TO_Pace2.isSelected()) {
			current = TravelPace.SLOW;
		} else if (radioBtn_TO_Pace3.isSelected()) {
			current = TravelPace.MEDIUM;
		} else {
			current = TravelPace.FAST;
		}
		return current;
	}
	
	/**
	 * gets whether or not the group has set out on the trail yet
	 * @return true if the group is on trail, false if its not
	 */
	public boolean isOnTrail(){
		return onTrail;
	}
	
	/**
	 * sets onTrail
	 * @param newOnTrail - if the group has been initalized
	 */
	public void setOnTrail(boolean newOnTrail){
		onTrail = newOnTrail;
	}
}
